package com.ipc.admin.controller.zzcool;

import com.ipc.admin.service.zzcool.service.AnnouncementService;
import com.ipc.common.pojo.zzcool.bo.AnnouncementBo;
import com.ipc.common.pojo.vo.R;
import com.ipc.core.entity.zzcool.Announcement;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Announcement)表控制层
 *
 * @author makejava
 * @since 2023-04-28 11:49:00
 */
@RestController
@RequestMapping(value = "/api/announcement/", produces = "application/json; charset=utf-8")
@CrossOrigin
@Api(tags = "系统公告模块")
public class AnnouncementController {
    /**
     * 服务对象
     */
    @Resource
    private AnnouncementService announcementService;

    /**
     * 动态查询所有数据
     *
     * @param bo 查询动态查询
     * @return 所有数据
     */
    @ApiOperation("动态查询所有数据")
    @GetMapping("selectAllWhere")
    public R selectAllWhere(@RequestBody AnnouncementBo bo) {
        return R.ok(announcementService.queryAllWhere(bo));
    }

    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @ApiOperation("查询所有数据")
    @GetMapping("selectAll")
    public R selectAll() {
        return R.ok(announcementService.queryAll());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("selectOne")
    public R selectOne(int id) {
        return R.ok(announcementService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param announcement 实体对象
     * @return 新增结果
     */
    @ApiOperation("新增数据")
    @PostMapping("insert")
    public R insert(@RequestBody Announcement announcement) {
        return R.ok(announcementService.save(announcement));
    }

    /**
     * 修改数据
     *
     * @param announcement 实体对象
     * @return 修改结果
     */
    @ApiOperation("修改数据")
    @PostMapping("update")
    public R update(@RequestBody Announcement announcement) {
        return R.ok(announcementService.updateById(announcement));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @ApiOperation("删除数据")
    @PostMapping("delete")
    public R delete(int id) {
        return R.ok(announcementService.del(id));
    }
}

